package com.example.cart_system.controller;

import com.example.cart_system.pojo.Goods;
import com.example.cart_system.pojo.Result;
import com.example.cart_system.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @PostMapping("/addgoods")
    public Result<Boolean> insertGoods(@RequestBody Goods goods) {
        goodsService.insertGoods(goods);
        return new Result<Boolean>().success(true);
    }

    @PostMapping("/goodslist")
    public Result<List<Goods>> selectAllGoods() {
        List<Goods> list = goodsService.selectAllGoods();
        return new Result<List<Goods>>().success(list);
    }

    @PostMapping("/deletegood")
    public Result<Boolean> deleteGoods(@RequestBody Goods goods) {
        goodsService.deleteGoods(goods);
        return new Result<Boolean>().success(true);
    }
}
